/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package library;

import com.mysql.jdbc.Driver;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author user
 */
public class Koneksi {
    
    private static Connection koneksi;
    
    public static Connection getKoneksi(){
        if(koneksi == null){
        try {
                Driver driver = new Driver();
                    DriverManager.registerDriver(driver);

                    String url = "jdbc:mysql://localhost:3306/integrasi";
                    String user = "root";
                    String password = "";

                    koneksi = DriverManager.getConnection(url, user, password);
                    System.out.println("koneksi sukses");
                } catch (SQLException ex) {
                    System.out.println(ex.getMessage());
                }    
        }
    return koneksi;
    }
    
    public static void closeConnection(){
        if(koneksi != null){
            try {
                koneksi.close();
            } catch (SQLException ex) {
                Logger.getLogger(Koneksi.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    
}
